<route lang="json5">
{
  style: {
    navigationBarTitleText: '政策详情',
  },
}
</route>

<template>
  <view class="view-wrap">
    <web-view v-if="webViewSrc" :src="webViewSrc"></web-view>
    <rich-text v-if="richTextContent" :nodes="richTextContent"></rich-text>
    <wd-status-tip v-if="!isLoading && noContent" image="content" tip="暂无内容" />
  </view>
</template>

<script setup>
import PolicyApi from '@/service/policy'

const richTextContent = ref('')
const webViewSrc = ref('')

const noContent = computed(() => {
  return !richTextContent.value && !webViewSrc.value
})

const isLoading = ref(false)
const getPolicyDetail = async (id) => {
  try {
    isLoading.value = true
    uni.showLoading({
      title: '加载中',
    })
    const { code, result } = await PolicyApi.getPolicyDetail(id)
    if (code === 200 && result) {
      const { detail, forwardUrl } = result
      richTextContent.value = detail
      if (richTextContent.value) {
        richTextContent.value = richTextContent.value?.replaceAll('&amp;', '&')

        console.log('richTextContent', richTextContent.value)
      }
      webViewSrc.value = forwardUrl
    }
    uni.hideLoading()
    isLoading.value = false
  } catch (e) {
    uni.hideLoading()
    isLoading.value = false
  }
}

onLoad((options) => {
  getPolicyDetail(options.id)
})
</script>

<style lang="scss" scoped>
.view-wrap {
  height: 100%;
  overflow-y: scroll;
}
</style>
